package cn.sccl.common.dao.impl;

import cn.sccl.common.model.BaseModel;
import cn.sccl.common.web.WebNames;
import cn.sccl.common.util.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * 兼容MSS的分页查询
 */
@Deprecated
public class BaseQuery extends BaseModel {
    /**
     * 默认的当前页
     */
    private static final int DEFAULT_CURRENT_PAGE = 1;
    /**
     * 默认的每页条数
     */
    private static final int DEFAULT_PAGE_SIZE = 20;
    /**
     * 当前页
     */
    private int currentPage = DEFAULT_CURRENT_PAGE;
    /**
     * 每页条数
     */
    private int pageSize = DEFAULT_PAGE_SIZE;
    /**
     * 总记录条数
     */
    private int total;
    /**
     * 开始的记录行数
     */
    private int start;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 排序列名
     */
    private String sortname;
    /**
     * 排序顺序:升序或者降序（asc or desc）
     */
    private String sortorder = "asc";

    /**
     * jqGrid时使用  默认的排序字段
     */
    private String sidx;

    /**
     * jqGrid时使用 默认的排序类型  asc desc
     */
    private String sord;

    private Long currentUserId;
    private String currentDepartmentNo;

    /**
     * 是否为集团超级系统管理员
     * 是：true;否：false
     */
    private Boolean jtSuperManagerFlag = Boolean.FALSE;
    /**
     * 是否为超级系统管理员
     * 是：true;否：false
     */
    private Boolean superManagerFlag = Boolean.FALSE;
    /**
     * 是否为采购处长
     * 是：true;否：false
     */
    private Boolean purchaseLeaderFlag = Boolean.FALSE;
    /**
     * 是否为部门领导
     * 是：true;否：false
     */
    private Boolean departmentLeaderFlag = Boolean.FALSE;


    /**
     * 是否为省公司超级系统管理员
     * 是：true;否：false
     */
    private Boolean provinceSuperManagerFlag = Boolean.FALSE;


    /**
     * 是否为市公司超级系统管理员
     * 是：true;否：false
     */
    private Boolean branchSuperManagerFlag = Boolean.FALSE;


    /* 是否为合同管理员
    * 是：true;否：false
    */
    private Boolean contractSuperManagerFlag = Boolean.FALSE;


    /**
     * 是否为分公司采购管理员
     * 是：true;否：false
     */
    private Boolean brancePurchaseSuperManagerFlag = Boolean.FALSE;

    /**
     * 是否为集1合同管理员角色
     * 是：true;否：false
     */
    private Boolean joneContractManagerFlag = Boolean.FALSE;

    /**
     * 是否为集二合同管理员角色
     * 是：true;否：false
     */
    private Boolean jtwoContractManagerFlag = Boolean.FALSE;

    /**
     * @return the defaultPageSize
     */
    public static int getDefaultPageSize() {
        return DEFAULT_PAGE_SIZE;
    }

    /**
     * @return the joneContractManagerFlag
     */
    public Boolean getJoneContractManagerFlag() {
        return joneContractManagerFlag;
    }

    /**
     * @param joneContractManagerFlag the joneContractManagerFlag to set
     */
    public void setJoneContractManagerFlag(Boolean joneContractManagerFlag) {
        this.joneContractManagerFlag = joneContractManagerFlag;
    }

    /**
     * @return the jtwoContractManagerFlag
     */
    public Boolean getJtwoContractManagerFlag() {
        return jtwoContractManagerFlag;
    }

    /**
     * @param jtwoContractManagerFlag the jtwoContractManagerFlag to set
     */
    public void setJtwoContractManagerFlag(Boolean jtwoContractManagerFlag) {
        this.jtwoContractManagerFlag = jtwoContractManagerFlag;
    }

    /**
     * @return the brancePurchaseSuperManagerFlag
     */
    public Boolean getBrancePurchaseSuperManagerFlag() {
        return brancePurchaseSuperManagerFlag;
    }

    /**
     * @param brancePurchaseSuperManagerFlag the brancePurchaseSuperManagerFlag to set
     */
    public void setBrancePurchaseSuperManagerFlag(Boolean brancePurchaseSuperManagerFlag) {
        this.brancePurchaseSuperManagerFlag = brancePurchaseSuperManagerFlag;
    }

    /**
     * @return the contractSuperManagerFlag
     */
    public Boolean getContractSuperManagerFlag() {
        return contractSuperManagerFlag;
    }

    /**
     * @param contractSuperManagerFlag the contractSuperManagerFlag to set
     */
    public void setContractSuperManagerFlag(Boolean contractSuperManagerFlag) {
        this.contractSuperManagerFlag = contractSuperManagerFlag;
    }

    /**
     * @return the jtSuperManagerFlag
     */
    public Boolean getJtSuperManagerFlag() {
        return jtSuperManagerFlag;
    }

    /**
     * @param jtSuperManagerFlag the jtSuperManagerFlag to set
     */
    public void setJtSuperManagerFlag(Boolean jtSuperManagerFlag) {
        this.jtSuperManagerFlag = jtSuperManagerFlag;
    }

    /**
     * @return the provinceSuperManagerFlag
     */
    public Boolean getProvinceSuperManagerFlag() {
        return provinceSuperManagerFlag;
    }

    /**
     * @param provinceSuperManagerFlag the provinceSuperManagerFlag to set
     */
    public void setProvinceSuperManagerFlag(Boolean provinceSuperManagerFlag) {
        this.provinceSuperManagerFlag = provinceSuperManagerFlag;
    }

    /**
     * @return the branchSuperManagerFlag
     */
    public Boolean getBranchSuperManagerFlag() {
        return branchSuperManagerFlag;
    }

    /**
     * @param branchSuperManagerFlag the branchSuperManagerFlag to set
     */
    public void setBranchSuperManagerFlag(Boolean branchSuperManagerFlag) {
        this.branchSuperManagerFlag = branchSuperManagerFlag;
    }

    /**
     * @return the sidx
     */
    public String getSidx() {
        return sidx;
    }

    /**
     * @param sidx the sidx to set
     */
    public void setSidx(String sidx) {
        this.sidx = sidx;
    }

    /**
     * @return the sord
     */
    public String getSord() {
        return sord;
    }

    /**
     * @param sord the sord to set
     */
    public void setSord(String sord) {
        this.sord = sord;
    }

    public Integer getCurrentPage() {
        // 未知开始的记录行数，已知当前页数
        if (start == 0)
            return this.currentPage;
        // 已知开始的记录行数，计算当前页数
        if (start > 0) {
            this.currentPage = (this.start - 1) / this.pageSize + 1;
        }
        return currentPage;
    }

    /**
     * @param currentPage the currentPage to set
     */
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getEnd() {
        int endRecord = 0;
        if (getTotal().intValue() == 0) {
            return endRecord;
        }
        endRecord = getPageSize() * getCurrentPage();
        if (endRecord > this.total) {
            endRecord = this.total;
        }
        this.totalPage = (total % pageSize) == 0 ? total / pageSize : total / pageSize + 1; // 计算总页数
        return endRecord;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    /**
     * @param pageSize the pageSize to set
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getStart() {
        // 已知开始的记录行数
        if (this.start > 0)
            return this.start;
        // 未知开始的记录行数,计算开始的记录行数
        int startRecord = this.pageSize * (this.currentPage - 1) + 1;
        if (startRecord >= this.total) {
            startRecord = this.total;
        }
        this.start = startRecord;
        return this.start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(int start) {
        this.start = start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getTotal() {
        return total;
    }

    /**
     * @param total the total to set
     */
    public void setTotal(int total) {
        this.total = total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * @return the sortname
     */
    public String getSortname() {
        return sortname;
    }

    /**
     * @param sortname the sortname to set
     */
    public void setSortname(String sortname) {
        this.sortname = sortname;
    }

    /**
     * @return the sortorder
     */
    public String getSortorder() {
        return sortorder;
    }

    /**
     * @param sortorder the sortorder to set
     */
    public void setSortorder(String sortorder) {
        this.sortorder = sortorder;
    }

    /**
     * @return 年份条件
     * @Title: getYear
     * @Description: 根据页面传递的年份信息初始化查询条件
     * @Author: bieby
     * @Date: 2014-2-13
     */
    @Override
    public Integer getYear() {
        if (super.getYear() == null || super.getYear().equals(WebNames.DataHistoryEnum.全部.getValue())) {
            return null;
        } else {
            Calendar c = Calendar.getInstance();
            Date dt = DateUtil.beforeYears(c.getTime(), super.getYear() - 1);
            c.setTime(dt);
            return c.get(Calendar.YEAR);
        }

    }

    /**
     * @return 原始年份
     * @Title: getOriginalYear
     * @Description: 获取原始年份信息
     * @Author: bieby
     * @Date: 2014-2-13
     */
    public Integer getOriginalYear() {
        return this.year;
    }


    public Boolean getSuperManagerFlag() {
        return superManagerFlag;
    }


    public void setSuperManagerFlag(Boolean superManagerFlag) {
        this.superManagerFlag = superManagerFlag;
    }


    public Boolean getPurchaseLeaderFlag() {
        return purchaseLeaderFlag;
    }


    public void setPurchaseLeaderFlag(Boolean purchaseLeaderFlag) {
        this.purchaseLeaderFlag = purchaseLeaderFlag;
    }


    public Boolean getDepartmentLeaderFlag() {
        return departmentLeaderFlag;
    }


    public void setDepartmentLeaderFlag(Boolean departmentLeaderFlag) {
        this.departmentLeaderFlag = departmentLeaderFlag;
    }


    public Long getCurrentUserId() {
        return currentUserId;
    }


    public void setCurrentUserId(Long currentUserId) {
        this.currentUserId = currentUserId;
    }


    public String getCurrentDepartmentNo() {
        return currentDepartmentNo;
    }


    public void setCurrentDepartmentNo(String currentDepartmentNo) {
        this.currentDepartmentNo = currentDepartmentNo;
    }

}
